<?php
include (dirname(__FILE__) . '/classes/FirePHP.php');
require (dirname(__FILE__) . '/config/config.inc.php');
require (dirname(__FILE__) . '/classes/Db.php');
require (dirname(__FILE__) . '/classes/Facebook_login.php');

if(isset($_SESSION['awesome_id']))
      header('Location: index.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $db = new DB();

    $id = $db->login($_POST['username'], $_POST['password'], $_POST['from']);

    if ($id) {
        $response = '{ "response":"success", "id":"'.$id.'" }';

        // if ($count >= 1) {
        // $response .= ', "achievements" : [';
        // }
        // while ($row = mysql_fetch_assoc($result)) {
        // $response .= json_encode($row) . ",";
        // }
        // $response = substr($response, 0, -1);
        // $response .= '] }';
        // SELECT a.* FROM user_achievement AS ua
        // JOIN achievement AS a ON ua.id_archievement = a.id WHERE ua.id_user = 1
        // SELECT * FROM pre_achievement
        // JOIN pre_achievement_lang AS lang ON pre_achievement.id_message  = lang.id
        // JOIN pre_category AS category ON pre_achievement.id_category = category.id
        // JOIN pre_category_lang AS category_lang ON category_lang.id_category = category.id WHERE category_lang .id_lang = 2 AND lang.id_lang = 2

        echo $response;
        return TRUE;
    } else {
        echo $response = '{ "response":"fail", "message": "Your Login Name or Password is invalid"}';
        return FALSE;
    }
}

if($user){
            $firebug = FirePHP::getInstance(true);
             $firebug->log($facebook);
        $firebug->log($user_profile);
         $firebug->log($user_profile['name']);
         $firebug->log($user_profile['id']);
    $db = new DB();
    $id = $db->login($user_profile['name'], $user_profile['id'], "facebook");
}
?>

            <link rel="stylesheet" type="text/css"  href="css/style.css"/>
           
    <div>
        <form id="form" action="" method="POST">
            <input type="hidden" name="from" value="awesomepeople"/>
            <label>User   :</label><input id="username" type="text" name="username" class="box"/>
            <label>Password  :</label><input id="password" type="password" name="password" class="box" />
            <input id="login_button" type="submit" value="submit"/><br />
            <div id="message"></div>
        </form>

        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
       
    </div>
